//
//  LoadingViewController.m
//  
//
//  Created by qkong on 15/6/12.
//
//

#import "LoadingViewController.h"
#import "UILoadingView.h"
#import "SideBarLeftViewController.h"
#import "QAirAppDelegate.h"
#define ACTIVE_INDICATOR_IMAGE @"ic_indicators_now"
#define UNACTIVE_INDICATOR_IMAGE @"ic_indicators_default"
@interface LoadingViewController ()

@property (weak, nonatomic) IBOutlet UILoadingView *loadingView;
@end

@implementation LoadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置图片
    self.loadingView.images = [self getLoadingImages];
    
    self.loadingView.activeIndicator = [UIImage imageNamed:ACTIVE_INDICATOR_IMAGE];
    self.loadingView.unActiveIndicator = [UIImage imageNamed:UNACTIVE_INDICATOR_IMAGE];
    [self.loadingView initIndicatorView];
    
    //设置进入按钮
    UIButton *enterBtn = [[UIButton alloc]initWithFrame:[self getEnterBtnFrame]];
    UIImage *enterBtnImage = [UIImage imageNamed:@"ic_into_arrow"];
    [enterBtn setBackgroundImage:enterBtnImage forState:UIControlStateNormal];
    [enterBtn addTarget:self action:@selector(enterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.loadingView.enterBtn = enterBtn;
}

- (void)enterBtnClick{
    QAirAppDelegate *delegate = (QAirAppDelegate *)[UIApplication sharedApplication].delegate;
    MFSideMenuContainerViewController *leftVC = delegate.container;
    [self presentViewController:leftVC animated:YES completion:nil];
}

- (CGRect)getEnterBtnFrame{;
    CGFloat width = 30;
    CGFloat height = 60;
    CGFloat x = self.loadingView.contentSize.width-width;
    CGFloat y = SCREEN_HEIGH/2-height/2;
    return CGRectMake(x, y, width, height);
}

- (CGRect)getEnterBtnFrame:(NSUInteger)imageCount{
    CGFloat btnWidth = 100;
    CGFloat btnHeight = 40;
    CGFloat btnX = SCREEN_WIDTH*imageCount - SCREEN_WIDTH/2 - btnWidth/2;
    CGFloat btnY = SCREEN_HEIGH - 100;
    return CGRectMake(btnX, btnY, btnWidth, btnHeight);
}


- (NSArray *)getLoadingImages{
    NSArray *imagesNameArray = @[@"qair_01.png",@"qair_02.png"];
    NSMutableArray *images = [[NSMutableArray alloc]init];
    for (NSString* imageName in imagesNameArray) {
        UIImage *image = [UIImage imageNamed:imageName];
        [images addObject:image];
    }
    return [images copy];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
